﻿using Microsoft.AspNetCore.Mvc;
using WMS_MAV;
using MVC_System.DTO.ProcessTask;
using MVC_System.DTO.Warehouse;

namespace MVC_System.Controllers
{
    public class ProcessTaskController : Controller
    {
        protected readonly IConfiguration _configuration;

        public ProcessTaskController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        /// <summary>
        /// 工序任务添加视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ProcessTaskAdd()
        {
            return View();
        }
        /// <summary>
        /// 工序任务显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ProcessTaskShow()
        {
            return View();
        }
        /// <summary>
        /// 工序任务详情视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ProcessTaskDetails()
        {
            return View();
        }

        /// <summary>
        /// 添加工序任务
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LocationProcessTaskAdd(PocessTaskAddDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "mhb/api/ProcessTask/ProcessTaskAdd";/*_configuration["Url"] + "mhb/api/Location/CreateLocation";*/
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }

        /// <summary>
        /// 工序任务显示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoProcessTaskShow(ProcessTaskShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "mhb/api/ProcessTask/ProcessTaskShow?pageiden="+ dto.pageIndex+ "&pageSzen="+ dto.pageSize+ "&taskMumber="+ dto.taskMumber+"&taskStatus="+ dto.taskStatus; /*_configuration["Url"] + "mhb/api/Warehouse/WarehouseShow?pageiden=" + dto.pageindex + "&pageSzen=" + dto.pagesize + "&warehouseNumber=" + dto.warehouseNumber + "&positionNumber=" + dto.positionNumber + "&warehouseState=" + dto.warehouseState;*/
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }

        /// <summary>
        /// 工序任务详API
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoProcessTaskDetails(ProcessTaskDetailsDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "mhb/api/ProcessTask/ProcessTaskDetails?processTaskId=" + dto.processTaskId;
                /*_configuration["Url"] + "mhb/api/Warehouse/WarehouseFan?warehouseID=" + dto.warehouseID;*/
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }

        /// <summary>
        /// 工序任务修改状态API
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> LedgerInfoProcessTaskupdate(ProcessTaskupdateDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "mhb/api/ProcessTask/ProcessTaskUpdate";
            var list = "{\"processTaskId\":" + dto.processTaskId + ",\"taskStatus\":" + dto.taskStatus + "}";
            var respomse = await client.PostAsync(url, list);
            return Json(respomse);
        }

    }
}
